Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Sep 17, 2025

Backport of #119229 to release/10.0

/cc @jeffhandley @copilot

Customer Impact

  • Customer reported
  • Found internally

As reported by a customer in Tensor.StdDev vs TensorPrimitives.StdDev differences for Complex input (dotnet/runtime#116133), the Tensor.StdDev API being stablized in .NET 10 reports incorrect results for complex numbers, while TensorPrimitives.StdDev produces the correct results.

Regression

  • Yes
  • No

This is a broken scenario on new APIs being marked as stable in .NET 10. The customer reported the issue against a preview, providing a repro that exhibited the incorrect results.

Testing

The customer's repro was used as the foundation for additional unit testing, with the tests verifying that Tensor and TensorPrimitives produce the same, expected results.

Risk

Low. Only the new Tensor.StdDev API is affected, and it now has Abs(x - mean) logic matching TensorPrimitives behavior. This algorithm also matches the behavior of other platforms' math libraries, including NumPy. The introduction of the Abs call will have a very minor perf hit, and approaches for avoiding that hit when unnecessary were discussed and ruled out as they would incur more substantial perf hits to conduct the check.

Copilot AI and others added 13 commits September 17, 2025 04:37
…tion

- Fix typo: "TensorPrimitivers" -> "TensorPrimitives" in test comment
- Replace custom SumOfSquaredMagnitudeDifferences operation with direct use of TensorPrimitives.StdDev
- Leverage TensorPrimitives vectorization optimizations where T.Abs is only called when necessary
- Remove unnecessary custom operation that always called T.Abs for all types
- Use TryGetSpan for contiguous tensors and fallback to FlattenTo for non-contiguous tensors

Co-authored-by: jeffhandley <[email protected]>
…or non-essential methods and convert StdDev tests to Theory tests

Co-authored-by: jeffhandley <[email protected]>
Added comment to clarify absolute value usage for complex numbers.
@jeffhandley jeffhandley requested a review from artl93 September 17, 2025 14:53
@jeffhandley
Copy link
Member

@artl93 Seeking your approval of this backport to 10.0 RC2, with it meeting the bug bar as a broken scenario in a new API.

Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RC2 - we should do math correctly.

@artl93 artl93 added the Servicing-approved Approved for servicing release label Sep 17, 2025
@artl93 artl93 merged commit ebaebee into release/10.0 Sep 17, 2025
90 of 91 checks passed
@jeffhandley jeffhandley deleted the backport/pr-119229-to-release/10.0 branch September 17, 2025 23:30
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants